#include <iostream>
#include <algorithm>
#include "checker.h"

Checker& Checker::m_instance = Checker();

Checker::Checker()
{
}

Checker::~Checker()
{
}

Checker& Checker::Instance()
{
	return (Checker::m_instance);
}

void Checker::addNew(void* const _address)
{
	m_new.push_back(_address);
}

void Checker::addDelete(void* const _address)
{
	m_delete.push_back(_address);
}

void Checker::check()
{
	int ko = 0;
	int ok = 0;
	std::vector<void* const>::const_iterator it = m_new.begin();
	for (; it != m_new.end(); ++it)
	{
		if (std::find(m_delete.begin(), m_delete.end(), *it) == m_delete.end())
		{
			std::cout << "PROBLEME: no delete found for: " << *it << std::endl;
			ko++;
		}
		else
			ok++;
	}
	std::cout << ok << " elements has been deleted on " << ok + ko << " (" << ko << " failled)" << std::endl;
}

void Checker::reset()
{
	m_new.clear();
	m_delete.clear();
}